package com.whfc.ms.api.sys.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.PageData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.fuum.dto.SysUserDTO;
import com.whfc.fuum.entity.SysUser;
import com.whfc.fuum.param.SysInnerUserAddParam;
import com.whfc.fuum.param.SysInnerUserEditParam;
import com.whfc.ms.api.sys.service.MsSysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @author: xugcheng
 * @version: 1.0
 * @date: 2019/7/16 11:05
 */
@RequiresPermissions(value = "sys/innerAccount")
@RestController
@RequestMapping("/ms/api/user/inner")
public class SysInnerUserController extends BaseController {

    @Autowired
    private MsSysUserService sysUserService;

    /**
     * 内部帐号列表
     *
     * @param sysUser
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    @GetMapping("/list")
    public Result innerUserList(@SessionAttribute(SessionAttr.MS_USER) SysUser sysUser,
                                @RequestParam("pageNum") Integer pageNum,
                                @RequestParam("pageSize") Integer pageSize,
                                @RequestParam(value = "keyword", required = false) String keyword) {
        logger.info("内部帐号列表,loginer:{},pageNum:{},pageSize:{},keyword:{}", sysUser.getUsername(), pageNum, pageSize, keyword);
        PageData<SysUserDTO> pageData = sysUserService.innerUserList(pageNum, pageSize, keyword);
        return ResultUtil.success(pageData);
    }

    /**
     * 添加内部帐号
     *
     * @param sysUser
     * @param request
     * @return
     */
    @PostMapping("/add")
    public Result innerUserAdd(@SessionAttribute(SessionAttr.MS_USER) SysUser sysUser, @RequestBody @Validated SysInnerUserAddParam request) {
        logger.info("添加内部帐号,loginer:{},param:{}", sysUser.getUsername(), request.toString());
        sysUserService.innerUserAdd(request);
        return ResultUtil.success();
    }

    /**
     * 编辑内部账号
     *
     * @param sysUser
     * @param request
     * @return
     */
    @PostMapping("/edit")
    public Result innerUserEdit(@SessionAttribute(SessionAttr.MS_USER) SysUser sysUser, @RequestBody @Validated SysInnerUserEditParam request) {
        logger.info("编辑内部账号，loginer:{},param:{}", sysUser.getUsername(), request.toString());
        sysUserService.innerUserEdit(request);
        return ResultUtil.success();
    }
}
